#include "ChineseEnglishMapping.h"

static ChineseEnglishMapping* s_ommonr = nullptr;
ChineseEnglishMapping::ChineseEnglishMapping()
{
    ModelNameToTitleMap.insert("350", "BD350");
    ModelNameToTitleMap.insert("1021", "CM1021");
    ModelNameToTitleMap.insert("1028", "CM1028");

    //350 listWidget
    ListWidgetTitle350Map.insert("Alarm.xml","Alarm.xml");
    ListWidgetTitle350Map.insert("AutoControl.xml","AutoControl.xml");
    ListWidgetTitle350Map.insert("CustomMoto-350.xml","CustomMoto-350.xml");
    ListWidgetTitle350Map.insert("CustomTempDiff.xml","CustomTempDiff.xml");
    ListWidgetTitle350Map.insert("Fan.xml","Fan.xml");
    ListWidgetTitle350Map.insert("GlobalParam.xml","GlobalParam.xml");
    ListWidgetTitle350Map.insert("IO.xml","IO.xml");
    ListWidgetTitle350Map.insert("MainPower.xml","MainPower.xml");
    ListWidgetTitle350Map.insert("Monitor.xml","Monitor.xml");
    ListWidgetTitle350Map.insert("Moto.xml","Moto.xml");
    ListWidgetTitle350Map.insert("SmokeSensor.xml","SmokeSensor.xml");
    ListWidgetTitle350Map.insert("TempSensor.xml","TempSensor.xml");
    ListWidgetTitle350Map.insert("user.xml","user.xml");
    //1021 listWidget
    ListWidgetTitle1021Map.insert("TempSensor.xml","TempSensor.xml");
    //1028 listWidget
    ListWidgetTitle1028Map.insert("AutoControl.xml","AutoControl.xml");
    ListWidgetTitle1028Map.insert("TempSensor.xml","TempSensor.xml");
    ListWidgetTitle1028Map.insert("AtDevice.xml","AtDevice.xml");

    //350 Alarm 表头
    Alarm350tableHeadMap.insert("code","code");
    Alarm350tableHeadMap.insert("name","name");
    Alarm350tableHeadMap.insert("desc","desc");
    Alarm350tableHeadMap.insert("prompt","prompt");
    Alarm350tableHeadMap.insert("opt_code","opt_code");
    Alarm350tableHeadMap.insert("req_user_lv","req_user_lv");
    //350 AutoControl 表头
    AutoControl350tableHeadMap.insert("name","name");
    AutoControl350tableHeadMap.insert("initrotateswtime","initrotateswtime");
    AutoControl350tableHeadMap.insert("rotatejdtime","rotatejdtime");
    AutoControl350tableHeadMap.insert("default","default");
    AutoControl350tableHeadMap.insert("reduce","reduce");
    AutoControl350tableHeadMap.insert("invariant","invariant");
    AutoControl350tableHeadMap.insert("initrotatepr","initrotatepr");
    AutoControl350tableHeadMap.insert("reducerotate","reducerotate");
    AutoControl350tableHeadMap.insert("riserotate","riserotate");
    AutoControl350tableHeadMap.insert("lowlmit","lowlmit");
    AutoControl350tableHeadMap.insert("uplmit","uplmit");
    AutoControl350tableHeadMap.insert("out_sensor","out_sensor");
    AutoControl350tableHeadMap.insert("in_sensor","in_sensor");
    //350 CustomMoto 表头
    CustomMoto350tableHeadMap.insert("name", "name");
    CustomMoto350tableHeadMap.insert("type", "type");
    CustomMoto350tableHeadMap.insert("currentlocation", "currentlocation");
    CustomMoto350tableHeadMap.insert("minstep", "minstep");
    CustomMoto350tableHeadMap.insert("maxstep", "maxstep");
    CustomMoto350tableHeadMap.insert("steppos", "steppos");
    CustomMoto350tableHeadMap.insert("maxspeed", "maxspeed");
    CustomMoto350tableHeadMap.insert("minspeed", "minspeed");
    CustomMoto350tableHeadMap.insert("movespeed", "movespeed");
    CustomMoto350tableHeadMap.insert("openpos", "openpos");
    CustomMoto350tableHeadMap.insert("closepos", "closepos");
    CustomMoto350tableHeadMap.insert("findzerotimes", "findzerotimes");
    CustomMoto350tableHeadMap.insert("minacc", "minacc");
    CustomMoto350tableHeadMap.insert("rigidity", "rigidity");
    CustomMoto350tableHeadMap.insert("timeinterval", "timeinterval");
    CustomMoto350tableHeadMap.insert("zeroposition", "zeroposition");
    CustomMoto350tableHeadMap.insert("zerostepover", "zerostepover");
    CustomMoto350tableHeadMap.insert("timerinterval", "timerinterval");
    CustomMoto350tableHeadMap.insert("enable", "enable");
    //350 CustomTempDiff 表头
    CustomTempDiff350tableHeadMap.insert("id","id");
    CustomTempDiff350tableHeadMap.insert("out_sensor","out_sensor");
    CustomTempDiff350tableHeadMap.insert("in_sensor","in_sensor");
    //350 Fan 表头
    Fan350tableHeadMap.insert("name", "name");
    Fan350tableHeadMap.insert("type", "type");
    Fan350tableHeadMap.insert("rotate", "rotate");
    Fan350tableHeadMap.insert("maxrotate", "maxrotate");
    Fan350tableHeadMap.insert("uplimit", "uplimit");
    Fan350tableHeadMap.insert("lowlimit", "lowlimit");
    Fan350tableHeadMap.insert("board_id", "board_id");
    Fan350tableHeadMap.insert("phyid", "phyid");
    Fan350tableHeadMap.insert("enable", "enable");
    Fan350tableHeadMap.insert("location", "location");
    Fan350tableHeadMap.insert("phymap", "phymap");
    //350 GlobalParam 表头
    GlobalParam350tableHeadMap.insert("name", "name");
    GlobalParam350tableHeadMap.insert("val", "val");
    GlobalParam350tableHeadMap.insert("unit", "unit");
    GlobalParam350tableHeadMap.insert("des", "des");
    GlobalParam350tableHeadMap.insert("edit", "edit");
    GlobalParam350tableHeadMap.insert("type", "type");
    GlobalParam350tableHeadMap.insert("uplimit", "uplimit");
    GlobalParam350tableHeadMap.insert("lowlimit", "lowlimit");
    //350 IO 表头
    IO350tableHeadMap.insert("name", "name");
    IO350tableHeadMap.insert("type", "type");
    IO350tableHeadMap.insert("chs", "chs");
    IO350tableHeadMap.insert("logic", "logic");
    IO350tableHeadMap.insert("phyid", "phyid");
    IO350tableHeadMap.insert("board_id", "board_id");
    //350 MainPower 表头
    MainPower350tableHeadMap.insert("ac_id", "ac_id");
    MainPower350tableHeadMap.insert("out_id", "out_id");
    MainPower350tableHeadMap.insert("name", "name");
    MainPower350tableHeadMap.insert("soft_id", "soft_id");
    //350 Monitor 表头
    Monitor350tableHeadMap.insert("name", "name");
    Monitor350tableHeadMap.insert("show_group", "show_group");
    //350 Moto 表头
    Moto350tableHeadMap.insert("name", "name");
    Moto350tableHeadMap.insert("type", "type");
    Moto350tableHeadMap.insert("currentlocation", "currentlocation");
    Moto350tableHeadMap.insert("speed", "speed");
    Moto350tableHeadMap.insert("maxspeed", "maxspeed");
    Moto350tableHeadMap.insert("board_id", "board_id");
    Moto350tableHeadMap.insert("phyid", "phyid");
    Moto350tableHeadMap.insert("enable", "enable");
    //350 SmokeSensor 表头
    SmokeSensor350tableHeadMap.insert("name", "name");
    SmokeSensor350tableHeadMap.insert("type", "type");
    SmokeSensor350tableHeadMap.insert("alarm", "alarm");
    SmokeSensor350tableHeadMap.insert("phyid", "phyid");
    SmokeSensor350tableHeadMap.insert("board_id", "board_id");
    SmokeSensor350tableHeadMap.insert("port", "port");
    //350 TempSensor 表头
    TempSensor350tableHeadMap.insert("name", "name");
    TempSensor350tableHeadMap.insert("type", "type");
    TempSensor350tableHeadMap.insert("alarm", "alarm");
    TempSensor350tableHeadMap.insert("limit", "limit");
    TempSensor350tableHeadMap.insert("board_id", "board_id");
    TempSensor350tableHeadMap.insert("phyid", "phyid");
    TempSensor350tableHeadMap.insert("port", "port");
    //350 user 表头
    user350tableHeadMap.insert("account", "account");
    user350tableHeadMap.insert("password", "password");
    user350tableHeadMap.insert("type", "type");
    user350tableHeadMap.insert("permission", "permission");

    //1021 TempSensor 表头
    TempSensor1021tableHeadMap.insert("name", "name");
    TempSensor1021tableHeadMap.insert("type", "type");
    TempSensor1021tableHeadMap.insert("alarm", "alarm");
    TempSensor1021tableHeadMap.insert("limit", "limit");
    TempSensor1021tableHeadMap.insert("board_id", "board_id");
    TempSensor1021tableHeadMap.insert("phyid", "phyid");
    TempSensor1021tableHeadMap.insert("port", "port");

    //1028 AutoControl 表头
    AutoControl1028tableHeadMap.insert("name", "name");
    AutoControl1028tableHeadMap.insert("val", "val");
    AutoControl1028tableHeadMap.insert("desc", "desc");
    AutoControl1028tableHeadMap.insert("AirInletTempDevi", "AirInletTempDevi");
    AutoControl1028tableHeadMap.insert("in_sensor", "in_sensor");
    AutoControl1028tableHeadMap.insert("out_sensor", "out_sensor");
    AutoControl1028tableHeadMap.insert("water_in_sensor", "water_in_sensor");
    AutoControl1028tableHeadMap.insert("water_out_sensor", "water_out_sensor");
    AutoControl1028tableHeadMap.insert("mode", "mode");
    AutoControl1028tableHeadMap.insert("gear", "gear");
    AutoControl1028tableHeadMap.insert("rotate", "rotate");
    AutoControl1028tableHeadMap.insert("angle", "angle");
    //1028 TempSensor 表头
    TempSensor1028tableHeadMap.insert("name", "name");
    TempSensor1028tableHeadMap.insert("type", "type");
    TempSensor1028tableHeadMap.insert("alarm", "alarm");
    TempSensor1028tableHeadMap.insert("limit", "limit");
    TempSensor1028tableHeadMap.insert("board_id", "board_id");
    TempSensor1028tableHeadMap.insert("phyid", "phyid");
    TempSensor1028tableHeadMap.insert("port", "port");
    //1028 AtDevice 表头
    AtDevice1028tableHeadMap.insert("name", "name");
    AtDevice1028tableHeadMap.insert("type", "type");
    AtDevice1028tableHeadMap.insert("rotate", "rotate");
    AtDevice1028tableHeadMap.insert("board_id", "board_id");
    AtDevice1028tableHeadMap.insert("port", "port");
    AtDevice1028tableHeadMap.insert("angle", "angle");
    AtDevice1028tableHeadMap.insert("test", "test");
}

ChineseEnglishMapping *ChineseEnglishMapping::getSingleon()
{
    if (!s_ommonr)
    {
        s_ommonr = new ChineseEnglishMapping();
    }
    return s_ommonr;
}

QStringList ChineseEnglishMapping::getTableWidgetHeadLabels(const QString &fileName, const QStringList &list)
{
    QStringList headlist;
    for (auto FieldName : list)
    {
        headlist << getTableWidgetHead(COMMONS->MachType, fileName, FieldName).toString();
    }
    return headlist;
}

QVariant ChineseEnglishMapping::getModelNameToTitle(const QVariant &key) const
{
    QVariant var;
    if (ModelNameToTitleMap.contains(key)) {
        var = ModelNameToTitleMap.value(key);
    }
    return var;
}

QVariant ChineseEnglishMapping::getListWidgetToTitle(const QString &dirname, const QVariant &key) const
{
    QVariant var;
    if(dirname == "350")
    {
        if (ListWidgetTitle350Map.contains(key)) {
            var = ListWidgetTitle350Map.value(key);
        }
    }
    else if(dirname == "1021")
    {
        if (ListWidgetTitle1021Map.contains(key)) {
            var = ListWidgetTitle1021Map.value(key);
        }
    }
    else if(dirname == "1028")
    {
        if (ListWidgetTitle1028Map.contains(key)) {
            var = ListWidgetTitle1028Map.value(key);
        }
    }
    return var;
}

QVariant ChineseEnglishMapping::getGroupBoxTitle(const QVariant &key) const
{
    QVariant var;
    if (GroupBoxTitleMap.contains(key)) {
        var = GroupBoxTitleMap.value(key);
    }
    return var;
}

QVariant ChineseEnglishMapping::getTableWidgetHead(const QString &dirname, const QString &fileName, const QVariant &key) const
{
    QVariant var;
    if(dirname == "350")
    {
        if(fileName == "Alarm.xml")
        {
            if (Alarm350tableHeadMap.contains(key)) {
                var = Alarm350tableHeadMap.value(key);
            }
        }
        else if(fileName == "AutoControl.xml")
        {
            if(AutoControl350tableHeadMap.contains(key)) {
                var = AutoControl350tableHeadMap.value(key);
            }
        }
        else if(fileName == "CustomMoto-350.xml")
        {
            if(CustomMoto350tableHeadMap.contains(key)) {
                var = CustomMoto350tableHeadMap.value(key);
            }
        }
        else if(fileName == "CustomTempDiff.xml")
        {
            if(CustomTempDiff350tableHeadMap.contains(key)) {
                var = CustomTempDiff350tableHeadMap.value(key);
            }
        }
        else if(fileName == "Fan.xml")
        {
            if(Fan350tableHeadMap.contains(key)) {
                var = Fan350tableHeadMap.value(key);
            }
        }
        else if(fileName == "GlobalParam.xml")
        {
            if(GlobalParam350tableHeadMap.contains(key)) {
                var = GlobalParam350tableHeadMap.value(key);
            }
        }
        else if(fileName == "IO.xml")
        {
            if(IO350tableHeadMap.contains(key)) {
                var = IO350tableHeadMap.value(key);
            }
        }
        else if(fileName == "MainPower.xml")
        {
            if(MainPower350tableHeadMap.contains(key)) {
                var = MainPower350tableHeadMap.value(key);
            }
        }
        else if(fileName == "Monitor.xml")
        {
            if(Monitor350tableHeadMap.contains(key)) {
                var = Monitor350tableHeadMap.value(key);
            }
        }
        else if(fileName == "Moto.xml")
        {
            if(Moto350tableHeadMap.contains(key)) {
                var = Moto350tableHeadMap.value(key);
            }
        }
        else if(fileName == "SmokeSensor.xml")
        {
            if(SmokeSensor350tableHeadMap.contains(key)) {
                var = SmokeSensor350tableHeadMap.value(key);
            }
        }
        else if(fileName == "TempSensor.xml")
        {
            if(TempSensor350tableHeadMap.contains(key)) {
                var = TempSensor350tableHeadMap.value(key);
            }
        }
        else if(fileName == "user.xml")
        {
            if(user350tableHeadMap.contains(key)) {
                var = user350tableHeadMap.value(key);
            }
        }
    }
    else if(dirname == "1021")
    {
        if(fileName == "TempSensor.xml")
        {
            if(TempSensor1021tableHeadMap.contains(key)) {
                var = TempSensor1021tableHeadMap.value(key);
            }
        }
    }
    else if(dirname == "1028")
    {
        if(fileName == "AutoControl.xml")
        {
            if(AutoControl1028tableHeadMap.contains(key)) {
                var = AutoControl1028tableHeadMap.value(key);
            }
        }
        else if(fileName == "TempSensor.xml")
        {
            if(TempSensor1028tableHeadMap.contains(key)) {
                var = TempSensor1028tableHeadMap.value(key);
            }
        }
        else if(fileName == "AtDevice.xml")
        {
            if(AtDevice1028tableHeadMap.contains(key)) {
                var = AtDevice1028tableHeadMap.value(key);
            }
        }
    }
    return var;
}
